package com.xc.xcrpc.loadbalancer;

import com.xc.xcrpc.spi.SpiLoader;
import lombok.extern.slf4j.Slf4j;

/**
 * 负载均衡器工厂（工厂模式，用于获取负载均衡器对象）
 * @author zqx
 * @since 2024/10/1
 */
@Slf4j
public class LoadBalancerFactory {


    static {
        log.info("加载负载均衡");
        SpiLoader.load(LoadBalancer.class);
        log.info("加载负载均衡完成");
    }

    /**
     * 默认负载均衡器
     */
    private static final LoadBalancer DEFAULT_LOAD_BALANCER = new RoundRobinLoadBalancer();

    /**
     * 获取实例
     */
    public static LoadBalancer getInstance(String key){
        return SpiLoader.getInstance(LoadBalancer.class,key);
    }

}
